#!/bin/bash
#while true;do netstat -lntup | grep ":80 " ;done

logfile=`date "+%Y-%m-%d_%H:%M"`
start() {
    nohup  node app.js > ./log/$logfile.log 0>&1 2>&1 & echo $! > pid
}
stop() {
    [ -f "pid" ] && {
    pid=`cat pid`
    }
    [ -z $pid ] && {
    return
    }
    kill -9 $pid
    rm pid
}
restart() {
    stop
    start
}
clear() {
	stop
    rm *.log
    rm pid
}


case $1 in
    start)
    start
    exit 0
    ;;
    stop)
    stop
    exit 0
    ;;
    restart)
    restart
    exit 0
    ;;
    clear)
    clear
    exit 0
    ;;
    *)
    echo "Usage : $0 {start|stop|restart|clear}"
    ;;
esac
